package com.inei.evaluaciondelacapacitacion.model.connection;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import com.inei.evaluaciondelacapacitacion.R;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class UtilDB extends SQLiteOpenHelper {

	public static final String DB="EvaluacionDeLaCapacitacion.db";
	
	public static final int VERSION=1;
	Context context;
	public UtilDB(Context context){
		super(context, DB, null, VERSION);
		this.context = context;
	}
	
	public UtilDB(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		String sql;
		InputStream in;
		Document doc;
		NodeList statements;
		int i;
		try {
			DocumentBuilder dbuilder = DocumentBuilderFactory.newInstance()
					.newDocumentBuilder();
			in = context.getResources()
					.openRawResource(R.raw.script);
			doc = dbuilder.parse(in, null);
			statements = doc.getElementsByTagName("script");
			for (i = 0; i < statements.getLength(); i++) {
				sql = statements.item(i).getChildNodes().item(0).getNodeValue();
				db.execSQL(sql);
			}
		} catch (Exception e) {

		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub

	}

}
